package com.xdf.xzymanagementsystem.service.impl;

import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.xdf.xzymanagementsystem.dao.PaymentMapper;
import com.xdf.xzymanagementsystem.entity.Payment;
import com.xdf.xzymanagementsystem.service.PaymentService;
import com.xdf.xzymanagementsystem.util.SystemUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Description : 服务层实现类，由代码生成器自动生成
 * @Author : chanchaw
 * @Date : 2025-3-22 10:27:04
 */
@Slf4j
@Service
public class PaymentServiceImpl extends ServiceImpl<PaymentMapper, Payment> implements PaymentService {
    @Autowired
    private PaymentMapper dao;
    @Autowired
    private SystemUtils systemUtils;

    //=================以上是自动生成的代码，自定义代码请写在下面==================
    @Override
    public int insertSelective(Payment record) {
        return dao.insertSelective(record);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateByPrimaryKeySelective(Payment record) {
        return dao.update(record);
    }

    @Override
    public Payment selectByPrimaryKey(Integer id) {
        return dao.selectOneById(id);
    }

    @Override
    public List<Map<String, Object>> selectGreyMeet(Date start, Date end, String clientName, Integer value) {
        if (start == null) start = new Date();
        if (end == null) end = new Date();
        if (StringUtils.isEmpty(clientName)) clientName = "";
        if (value == null) value = 0;
        List<Map<String, Object>> list = dao.selectGreyMeet(start, end, clientName, value);
        return list;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int deleteByPrimaryKey(Integer id) {
        Payment payment = dao.selectOneById(id);
        payment.setIsDelete(1);
        payment.setLastUser(systemUtils.getLoginUsername());
        payment.setLastTime(new Date());
        return dao.update(payment);
    }

    @Override
    public List<Map<String, Object>> selectDyeingMeet(Date start, Date end, String clientName, Integer value) {
        if (start == null) start = new Date();
        if (end == null) end = new Date();
        if (StringUtils.isEmpty(clientName)) clientName = "";
        if (value == null) value = 0;
        List<Map<String, Object>> list = dao.selectDyeingMeet(start, end, clientName, value);
        return list;
    }

    @Override
    public List<Map<String, Object>> selectDeepMeet(Date start, Date end, String clientName, Integer value) {
        if (start == null) start = new Date();
        if (end == null) end = new Date();
        if (StringUtils.isEmpty(clientName)) clientName = "";
        if (value == null) value = 0;
        List<Map<String, Object>> list = dao.selectDeepMeet(start, end, clientName, value);
        return list;
    }

    @Override
    public List<Map<String, Object>> selectClientCollect(Date start, Date end, String clientName, Integer value) {
        if (start == null) start = new Date();
        if (end == null) end = new Date();
        if (StringUtils.isEmpty(clientName)) clientName = "";
        if (value == null) value = 0;
        List<Map<String, Object>> list = dao.selectClientCollect(start, end, clientName, value);
        return list;
    }
}